home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / devel / vbcc-68k-src / machines / amiga68k / libsrc / prof / prof_sysdep.c next >
C/C++ Source or Header  |  1999-01-01  |  2KB  |  79 lines

  1. /* $VER: pro_sysdep.c V0.2 (31.08.98)
  2.  *
  3.  * Portable profiler for vbcc. AMIGA OS/68k specific part.
  4.  * Copyright (c) 1998  Frank Wille
  5.  *
  6.  * The vbcc profiler is split into a system independant (profiler)
  7.  * and in a system specific (prof_sysdep) part.
  8.  *
  9.  * v0.2  (31.08.98) phx
  10.  *       Make sure profiler doesn't crash under Kickstart 1.x.
  11.  * v0.1  (28.08.98) phx
  12.  *       File created.
  13.  */
  14.  
  15. #include <exec/types.h>
  16. #include <exec/execbase.h>
  17. #include <devices/timer.h>
  18. #include <proto/exec.h>
  19. #include <stdio.h>
  20.  
  21. void _GetSysTime(__reg("a0") struct timeval *,
  22.                  __reg("a6") void *) = "\tjsr\t-66(a6)";
  23.  
  24. static void *timerbase = NULL;
  25. static struct IORequest *timerio;
  26. static struct timeval start;
  27.  
  28.  
  29. int _prof_inittimer()
  30. {
  31.   struct MsgPort *timerport;
  32.  
  33.   if (SysBase->LibNode.lib_Version < 36)
  34.     return (0);
  35.   if (timerport = CreateMsgPort()) {
  36.     if (timerio = CreateIORequest(timerport,sizeof(struct timerequest))) {
  37.       if (OpenDevice(TIMERNAME,UNIT_MICROHZ,timerio,0) == 0) {
  38.         timerbase = timerio->io_Device;
  39.       }
  40.       else {
  41.         DeleteIORequest(timerio);
  42.         DeleteMsgPort(timerport);
  43.       }
  44.     }
  45.     else
  46.       DeleteMsgPort(timerport);
  47.   }
  48.   if (!timerbase) {
  49.     fprintf(stderr,"_prof_inittimer: Can't get timer.device for profiling!\n");
  50.     return (0);
  51.   }
  52.   _GetSysTime(&start,timerbase);
  53.   return (1);
  54. }
  55.  
  56.  
  57. void _prof_timerexit()
  58. {
  59.   if (timerbase) {
  60.     if (!CheckIO(timerio)) {
  61.       AbortIO(timerio);
  62.       WaitIO(timerio);
  63.     }
  64.     CloseDevice(timerio);
  65.     DeleteMsgPort(timerio->io_Message.mn_ReplyPort);
  66.     DeleteIORequest(timerio);
  67.   }
  68. }
  69.  
  70.  
  71. unsigned long _prof_time()
  72. {
  73.   static struct timeval tv;
  74.  
  75.   _GetSysTime(&tv,timerbase);
  76.   return (((long)tv.tv_secs-(long)start.tv_secs)*1000000 +
  77.           ((long)tv.tv_micro-(long)start.tv_micro));
  78. }
  79.